package com.atguigu.jxc.controller;

import com.atguigu.jxc.annotation.Log;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.SaleList;
import com.atguigu.jxc.entity.SaleListGoods;
import com.atguigu.jxc.service.SaleGoodsService;
import com.atguigu.jxc.service.SaleListGoodsService;
import com.atguigu.jxc.to.ReturnCountTo;
import com.atguigu.jxc.to.SaleCountTo;
import com.atguigu.jxc.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: lshuaib
 * @create: 2021-03-08 10:47
 * @description: 对销售单进行操作
 */
@RestController
@RequestMapping("/saleListGoods")
public class SaleGoodsController {
    @Autowired
    SaleGoodsService saleGoodsService;
    @Autowired
    SaleListGoodsService saleListGoodsService;

    /**
     * 保存销售单
     */
    @PostMapping("/save")
    public Map<String, Object> save(@RequestParam("saleNumber") String saleNumber, SaleList saleList, String saleListGoodsStr, HttpSession session) {
        Map<String, Object> map = new HashMap<>();
        try {
            saleGoodsService.save(saleNumber, saleList, saleListGoodsStr, session);
        } catch (Exception e) {
            e.printStackTrace();
        }
        map.put("code", 100);
        map.put("msg", "请求成功");
        map.put("info", null);
        return map;
    }

    @PostMapping("list")
    public Map<String, Object> list(@RequestParam(value = "saleNumber", required = false) String saleNumber,
                                    @RequestParam(value = "customerId", required = false) Integer customerId,
                                    Integer state, String sTime, String eTime) {
        return saleGoodsService.list(saleNumber, customerId, state, sTime, eTime);
    }

    @PostMapping("/goodsList")
    public Map<String, Object> goodsList(Integer saleListId) {
        return saleListGoodsService.goodsListBySaleListId(saleListId);
    }

    @PostMapping("updateState")
    public ServiceVO updateState(Integer saleListId) {

        return null;
    }

    @PostMapping("/getSaleDataByMonth")
    public List<Map<String, Object>> getSaleDataByMonth(String sTime, String eTime) {
        return saleGoodsService.getSaleDataByMonth(sTime, eTime);
    }

    @PostMapping("/delete")
    public ServiceVO delete(Integer saleListId) {
        try {
            saleGoodsService.delete(saleListId);
            return new ServiceVO(100, "请求成功", null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     * @Description: //TODO 按日统计接口
     * @Param: [java.lang.String, java.lang.String]
     * @return: java.util.List<java.util.Map>
     * @Version: 1.0
     * @Date: 2021/3/8 20:56
     * @Author: HanSan·胡
     **/
    @Log(logType = "查询操作", logContent = "商品销售按日统计")
    @PostMapping("/getSaleDataByDay")
    public List<Map> getSaleDataByDay(String sTime, String eTime){
        List<Map> saleDataByDay = saleListGoodsService.getSaleDataByDay(sTime, eTime);
        return saleDataByDay;
    }
    
    /**
     * @Description: //TODO 销售统计（可根据 商品类别、商品编码或名称 条件查询）
     * @Param: 
     * @return:  
     * @Version: 1.0
     * @Date: 2021/3/9 9:51        
     * @Author: HanSan·胡
     **/

    @Log(logType = "查询操作",logContent = "销售统计")
    @PostMapping("/count")
    public List<Map> count(SaleCountTo saleCountTo){
        return saleListGoodsService.count(saleCountTo);
    }



}
